<?php
/**
 * Created by C.
 * User: C
 * Date: 3.12.12
 * Time: 15:20
 */

class UsersController extends AppController {

    public function beforeFilter() { //määrame millistele actionitele pääseb ligi ilma sisse logimata
        parent::beforeFilter();
        $this->Auth->allow('index', 'login', 'logout');
    }

    public function index() {
        $this->redirect($this->login());
    }


    public function login() {
        if ($this->request->is('post')) {
            if ($this->Auth->login()) {
                $this->redirect($this->Auth->redirect());
            } else {
                $this->Session->setFlash(__('Vigane kasutajatunnus või parool'));
            }
        }
    }

    public function logout() {
        $this->redirect($this->Auth->logout());
    }
}